package cn.ybk.basic.dto;


import cn.ybk.basic.util.MD5Utils;
import cn.ybk.basic.util.StrUtils;
import cn.ybk.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class EmailDto {

    // 邮箱
    @NotBlank(message = "邮箱不能为空")
    private String email;
    // 邮箱验证码
    @NotBlank(message = "邮箱验证码不能为空")
    private String emailCode;
    // 密码
    @NotBlank(message = "密码不能为空")
    private String emailPassword;
    // 确认密码
    @NotBlank(message = "确认密码不能为空")
    private String emailPasswordRepeat;

    public User getUser(){
        String salt = StrUtils.getComplexRandomString(32);
        String pwd = MD5Utils.encrypByMd5(salt + this.emailPassword);
        return User
                .builder()
                .createtime(new Date())
                .state(1)
                .email(this.email)
                .password(pwd)
                .salt(salt)
                .username(this.email)
                .build();
    }

}
